package com.yanzhu.api;

import com.yanzhu.bean.ResponseBean;
import com.yanzhu.service.MaterialService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: 方炎柱
 * @Description:
 * @Date: Created in 20:22 2018/1/31
 * @Modified:
 */
@AllArgsConstructor
@RestController
public class MaterialAPI {
    private MaterialService materialService;

    @RequestMapping(value="/queryMaterialListByTid")
    public ResponseBean queryMaterialListByTid(HttpServletRequest request) throws Exception {
        String tid = request.getParameter("tid");
        if(tid == null || tid.equals(""))

            return ResponseBean.fail("缺少模版ID参数!");
        return ResponseBean.ok(materialService.queryMaterialListByTid(Long.parseLong(tid)));
    }

    @RequestMapping(value="/queryMaterialById")
    public ResponseBean queryMaterialById(HttpServletRequest request) throws Exception {
        String mid = request.getParameter("mid");
        if(mid == null || mid.equals(""))
            return ResponseBean.fail("缺少素材ID参数!");

        return ResponseBean.ok(materialService.queryMaterialById(Long.parseLong(mid)));
    }
}
